/*
 * SecurityService.java
 *
 * Copyright 2012 the original author or authors(ninglong).
 *
 * Licensed under the web-geek, Version 1.0 (the "License");
 *
 */
package org.geek.login.service.impl;

import javax.annotation.Resource;

import org.geek.domain.User;
import org.geek.login.domain.SecurityUser;
import org.geek.login.service.ISecurityService;
import org.geek.user.service.IUserService;
import org.geek.user.service.impl.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * <p></p>
 * @author ninglong bhd2973@qq.com
 * @version V1.0
 */
@Service
public class SecurityService implements ISecurityService {
	
	private static Logger logger = LoggerFactory.getLogger(SecurityService.class);
	@Resource
	private IUserService userService ;
	
	/**
	 * <p>根据用户名获取用户信息</p>
	 */
	public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
		User user = null;
		try {
			user = userService.getUserByAccount(userName);
			if(user == null){
				logger.debug("没有此用户名");
				return null ;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new SecurityUser(user);
	}
	
	/**
	 * @param userService the userService to set
	 */
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
}
